home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 July: Mac OS SDK / Dev.CD Jul 97 SDK2.toast / Development Kits (Disc 2) / QuickTime™ VR 2.0 SDK / QTVR C⁄C++ Runtime API / Sample Code / VRShell Sample Code / VRShell / Application Files / MacApplication.c < prev    next >
Encoding:
Text File  |  1997-05-22  |  8.2 KB  |  399 lines  |  [TEXT/MPCC]

  1. //
  2. //    File:        MacApplication.c
  3. //
  4. //    Contains:    Functions that could be overridden in a specific application.
  5. //
  6. //    Written by:    Tim Monroe
  7. //                Based (heavily!) on the MovieShell code written by Apple DTS
  8. //
  9. //    Copyright:    © 1994-1996 by Apple Computer, Inc., all rights reserved.
  10. //
  11. //    Change History (most recent first):
  12. //
  13. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  14. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  15. //       <2>         11/27/96    rtm        conversion to personal coding style;
  16. //                                    added preliminary QTVR support
  17. //       <1>         12/21/94    khs        first file
  18. //       
  19. //
  20.  
  21. // header files
  22. #include "MacApplication.h"
  23. #include "MacFramework.h"
  24. #include "AppConfiguration.h"
  25. #include "DTSQTUtilities.h"
  26. #include "QTVRUtilities.h"
  27.  
  28. // Header file for the specific test functions.
  29. #include "TestFunctions.h"
  30.  
  31. // global variables
  32. long gMaxMilliSecToUse = kMaxMilliSecToUse;        
  33.  
  34.  
  35. //////////
  36. //
  37. // InitApplication
  38. // Do any application-specific initialization.
  39. //
  40. //////////
  41.  
  42. void InitApplication (void)
  43. {
  44.     // make sure that the QTVR Manager is present in the present operating environment
  45.     if (!QTVRUtils_IsQTVRMgrInstalled()) {
  46.         ShowWarning("\pThe QuickTime VR Manager cannot be found.", 0);
  47.         //ExitToShell();
  48.     }
  49. }
  50.  
  51.  
  52. //////////
  53. //
  54. // StopApplication
  55. // Do any application-specific shut-down.
  56. //
  57. //////////
  58.  
  59. void StopApplication (void)
  60. {
  61.     // @@@INSERT APPLICATION-SPECIFIC SHUT-DOWN FUNCTIONALITY HERE
  62.  
  63. }
  64.  
  65.  
  66. //////////
  67. //
  68. // DoIdle
  69. // Do any processing that can/should occur at idle time.
  70. //
  71. //////////
  72.  
  73. void DoIdle (WindowRef theWindow)
  74. {
  75.     GrafPtr             mySavedPort;
  76.     WindowObject         myWindowObject;
  77.     MovieController        myMC = NULL;
  78.     Point                myPoint;
  79.     
  80.     GetPort(&mySavedPort);
  81.     SetPort(theWindow);
  82.     
  83.     myWindowObject = (WindowObject) GetWRefCon(theWindow);
  84.     if (myWindowObject != NULL) {
  85.     
  86.         myMC = (**myWindowObject).fController;
  87.         if (myMC != NULL) {
  88.         
  89.             MoviesTask(MCGetMovie(myMC), gMaxMilliSecToUse);
  90.  
  91.             //restore the cursor to the arrow if it's outside the movie window
  92.             //and the mouse button isn't still down;
  93.             //this is needed only for VR movies, but should probably always be done
  94.             if (theWindow == FrontWindow()) {
  95.                 GetMouse(&myPoint);
  96.                 if (!PtInMovie(MCGetMovie(myMC), myPoint) && !StillDown())
  97.                     InitCursor();
  98.             }
  99.         }
  100.     }
  101.  
  102.     // @@@INSERT ANY OTHER IDLE-BASED FUNCTIONALITY HERE
  103.  
  104.     SetPort(mySavedPort);
  105. }
  106.  
  107.  
  108. //////////
  109. //
  110. // DoUpdateWindow
  111. // Update the specified window.
  112. //
  113. //////////
  114.  
  115. void DoUpdateWindow (WindowRef theWindow, Rect *theRefreshArea)
  116. {
  117.     GrafPtr             mySavedPort;
  118.     
  119.     GetPort(&mySavedPort);
  120.     SetPort(theWindow);
  121.     
  122.     BeginUpdate(theWindow);
  123.  
  124.     EraseRect(theRefreshArea);        // this is important, for non-rectangular movies
  125.     
  126.     // @@@INSERT WINDOW-SPECIFIC DRAWING FUNCTIONALITY HERE
  127.  
  128.     EndUpdate(theWindow);
  129.     SetPort(mySavedPort);
  130. }
  131.  
  132.  
  133. //////////
  134. //
  135. // HandleContentClick
  136. // Handle mouse button clicks in the specified window.
  137. //
  138. //////////
  139.  
  140. void HandleContentClick (WindowRef theWindow, EventRecord *theEvent)
  141. {
  142.     GrafPtr             mySavedPort;
  143.     
  144.     GetPort(&mySavedPort);
  145.     SetPort(theWindow);
  146.  
  147.     // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  148.  
  149.     SetPort(mySavedPort);
  150. }
  151.  
  152.  
  153. //////////
  154. //
  155. // HandleQTVRKeyPress
  156. // Handle QuickTime VR-specific key presses.
  157. // Returns true if the key press was handled, false otherwise.
  158. //
  159. //////////
  160.  
  161. Boolean HandleQTVRKeyPress (EventRecord *theEvent)
  162. {
  163.     Boolean        isHandled = true;
  164.     char        myCharCode;
  165.     
  166.     myCharCode = theEvent->message & charCodeMask;
  167.  
  168.     switch (myCharCode) {
  169.         case '-':
  170.             // decrease Pan 1 degree
  171.             //mQTVRChangePan(nil, -1.0);
  172.             break;
  173.         case '+':
  174.             // decrease Pan 1 degree
  175.             //mQTVRChangePan(nil, 1.0);
  176.             break;
  177.  
  178.         // take keypad keys as a nudge in the appropriate direction
  179.         case '1':
  180.             //mQTVRNudge(kQTVRDownLeft);
  181.             break;
  182.         case '2':
  183.             //mQTVRNudge(kQTVRDown);
  184.             break;
  185.         case '3':
  186.             //mQTVRNudge(kQTVRDownRight);
  187.             break;
  188.         case '4':
  189.             //mQTVRNudge(kQTVRLeft);
  190.             break;
  191.         case '6':
  192.             //mQTVRNudge(kQTVRRight);
  193.             break;
  194.         case '7':
  195.             //mQTVRNudge(kQTVRUpLeft);
  196.             SysBeep(30);
  197.             break;
  198.         case '8':
  199.             //mQTVRNudge(kQTVRUp);
  200.             break;
  201.         case '9':
  202.             //mQTVRNudge(kQTVRUpRight);
  203.             break;
  204.  
  205.         default:
  206.             isHandled = false;
  207.             break;
  208.     }
  209.  
  210.     return(isHandled);
  211. }
  212.  
  213.  
  214. //////////
  215. //
  216. // CreateMovieWindow
  217. // Create a window to display a movie in.
  218. //
  219. //////////
  220.  
  221. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  222. {
  223.     WindowRef            myWindow;
  224.         
  225.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  226.     return(myWindow);
  227. }
  228.  
  229.  
  230. //////////
  231. //
  232. // HandleApplicationMenu
  233. // Handle selections in the application's menus.
  234. //
  235. //////////
  236.  
  237. void HandleApplicationMenu (short theMenuID, short theMenuItem)
  238. {
  239.     MovieController     myMC = NULL;
  240.     
  241.     switch (theMenuID) {
  242.         case mTesting:
  243.             switch(theMenuItem) {
  244.                 case iTest1:
  245.                     // @@@INSERT YOUR TEST FUNCTION 1 HERE
  246.                     myMC = GetMCFromFrontWindow();
  247.                     if (myMC != NULL) {
  248.                         QTVRUtils_HideControllerBar(myMC);
  249.                     }
  250.                     break;
  251.                 
  252.                 case iTest2:
  253.                     // @@@INSERT YOUR TEST FUNCTION 2 HERE
  254.                     myMC = GetMCFromFrontWindow();
  255.                     if (myMC != NULL) {
  256.                         QTVRUtils_ShowControllerBar(myMC);
  257.                     }
  258.                     break;
  259.                 
  260.                 case iTest3:
  261.                     // @@@INSERT YOUR TEST FUNCTION 3 HERE
  262.                     myMC = GetMCFromFrontWindow();
  263.                     if (myMC != NULL) {
  264.                         QTVRUtils_HideControllerButton(myMC, kQTVRHotSpotButton);
  265.                     }
  266.                     break;
  267.                     
  268.                 case iTest4:
  269.                     // @@@INSERT YOUR TEST FUNCTION 3 HERE
  270.                     myMC = GetMCFromFrontWindow();
  271.                     if (myMC != NULL) {
  272.                         QTVRUtils_ShowControllerButton(myMC, kQTVRHotSpotButton);
  273.                     }
  274.                     break;
  275.             }
  276.             break;
  277.     }
  278. }
  279.  
  280.  
  281. //////////
  282. //
  283. // AdjustApplicationMenus
  284. // Adjust state of items in the application's menus.
  285. //
  286. //////////
  287.  
  288. void AdjustApplicationMenus (void)
  289. {
  290.     WindowRef             myWindow = NULL;
  291.     MovieController     myMC = NULL;
  292.     
  293.     myMC = GetMCFromFrontWindow();
  294.     if (myMC != NULL) {
  295.         EnableItem(GetMHandle(mTesting), iTest1);
  296.         EnableItem(GetMHandle(mTesting), iTest2);
  297.         EnableItem(GetMHandle(mTesting), iTest3);
  298.         EnableItem(GetMHandle(mTesting), iTest4);
  299.     } else {
  300.         DisableItem(GetMHandle(mTesting), iTest1);
  301.         DisableItem(GetMHandle(mTesting), iTest2);
  302.         DisableItem(GetMHandle(mTesting), iTest3);
  303.         DisableItem(GetMHandle(mTesting), iTest4);
  304.     }
  305.     
  306.     DisableItem(GetMHandle(mFile), iNew);        // we don't allow creating new VR files here...
  307.     DisableItem(GetMHandle(mFile), iPrint);        // currently printing causes crashes; FIX!
  308. }
  309.  
  310.  
  311. //////////
  312. //
  313. // AddControllerFunctionality
  314. // Configure the movie controller.
  315. //
  316. //////////
  317.  
  318. void AddControllerFunctionality (MovieController theMC)
  319. {
  320.     long            myControllerFlags;
  321.     
  322.     // CLUT table use    
  323.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  324.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  325.  
  326.     // enable keyboard event handling    
  327.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  328.     
  329.     // disable drag support
  330.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  331. }
  332.  
  333.  
  334. //////////
  335. //
  336. // InitApplicationWindowObject
  337. // Do any application-specific initialization of the window object.
  338. //
  339. //////////
  340.  
  341. void InitApplicationWindowObject (WindowObject theWindowObject)
  342. {
  343.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT INITIALIZATION HERE
  344. }
  345.  
  346.  
  347. //////////
  348. //
  349. // RemoveApplicationWindowObject
  350. // Do any application-specific clean-up of the window object.
  351. //
  352. //////////
  353.  
  354. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  355. {
  356.     OSErr                myErr = noErr;
  357.     QTVRInstance        myInstance = NULL;
  358.         
  359.     if (theWindowObject == NULL)
  360.         return;
  361.         
  362.     myInstance = (**theWindowObject).fInstance;
  363.     
  364.     // @@@INSERT APPLICATION-SPECIFIC WINDOW OBJECT CLEAN-UP HERE
  365.  
  366.     // DoDestroyMovieWindow in MacFramework.c releases the window object itself
  367. }
  368.  
  369.  
  370. //////////
  371. //
  372. // ApplicationMCActionFilterProc 
  373. // Intercept some mc actions for the QuickTime VR movie controller.
  374. //
  375. //////////
  376.  
  377. pascal Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, WindowRef theWindow)
  378. {
  379.     Boolean        isHandled = false;
  380.     
  381.     switch (theAction) {
  382.     
  383.         // handle window resizing
  384.         case mcActionControllerSizeChanged: {
  385.             Rect                myMovieBounds;
  386.  
  387.             MCGetControllerBoundsRect(theMC, &myMovieBounds);
  388.             SizeWindow((WindowPtr)theWindow, myMovieBounds.right - myMovieBounds.left,
  389.                                              myMovieBounds.bottom - myMovieBounds.top, true);
  390.             break;
  391.         }
  392.                         
  393.         default:
  394.             break;
  395.     }
  396.     
  397.     return(isHandled);    
  398. }
  399.